// pages/feedback/feedback.js
import { suggest, completeInfo } from '../../utils/api.js'
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },
    formSubmit: function (e) {
        var content = e.detail.value.content;
        this.setData({
            content: content
        })
        if (content) {
            if (app.globalData.phone && app.globalData.university) {
                var promise = new Promise((resolve, reject) => {
                    this.setData({
                        show: false
                    });
                    wx.showToast({
                        title: '反馈成功',
                        icon: 'success',
                        duration: 1500,
                        success: function () {
                            setTimeout(resolve, 1500)
                        }
                    })
                })
                promise.then(() => {
                    suggest('2', this.data.content, (res) => {
                        wx.switchTab({
                            url: '/pages/about/about',
                        })
                    })
                })
            } else if (!app.globalData.phone && app.globalData.university) {
                var promise = new Promise((resolve, reject) => {
                    wx.showToast({
                        title: '请补全手机号',
                        icon: 'none',
                        duration: 1500,
                        success: function () {
                            setTimeout(resolve, 1500)
                        }
                    })
                })
                promise.then(() => {
                    this.setData({
                        show: true,
                        arr: [{
                            id: 2,
                            name: 'phoneNum',
                            placeholder: '请输入您手机号'
                        }]
                    })
                })
            } else if (app.globalData.phone && !app.globalData.university) {
                var promise = new Promise((resolve, reject) => {
                    wx.showToast({
                        title: '请补全大学信息',
                        icon: 'none',
                        duration: 1500,
                        success: function () {
                            setTimeout(resolve, 1500)
                        }
                    })
                })
                promise.then(() => {
                    this.setData({
                        show: true,
                        arr: [{
                            id: 1,
                            name: 'university',
                            placeholder: '请输入您所在大学'
                        }]
                    })
                })
            } else {
                var promise = new Promise((resolve, reject) => {
                    wx.showToast({
                        title: '请补全个人信息',
                        icon: 'none',
                        duration: 1500,
                        success: function () {
                            setTimeout(resolve, 1500)
                        }
                    })
                })
                promise.then(() => {
                    this.setData({
                        show: true,
                        arr: [{
                            id: 1,
                            name: 'university',
                            placeholder: '请输入您所在大学'
                        },
                        {
                            id: 2,
                            name: 'phoneNum',
                            placeholder: '请输入您手机号'
                        }
                        ]
                    })
                })
            }
        } else {
            wx.showToast({
                title: '内容不能为空',
                icon: 'none',
                duration: 1500
            })
        }

    },
    util: function (e) {
        if (e.detail) {
            var promise = new Promise((resolve, reject) => {
                if (app.globalData.university || app.globalData.phone) {
                    completeInfo(app.globalData.university, app.globalData.phone, () => {
                        wx.showToast({
                            title: '信息补充完成',
                            icon: 'success',
                            duration: 1500,
                            success: function () {
                                setTimeout(resolve, 1500)
                            }
                        })
                    })
                }
            })
            promise.then(() => {
                suggest('2', this.data.content, (res) => {
                    wx.switchTab({
                        url: '/pages/about/about',
                    })
                })
            })
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {


    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})